<?

// GET THE UPPER AND LOWER BOUNDS FOR THE TIME PERIOD
function get_upper_lower()
{
	global $upperbound, $lowerbound, $fromdate, $todate, $date;

	// SET NUMBER OF DAYS IN SELECTED MONTH
//	if ($mon == 0)
//		$no_days = 0;
//	else $no_days = date("t", mktime(0,0,0,$mon,1,$yr) );//Láº¥y sá»‘ ngÃ y trong thÃ¡ng Ä‘Ã³ 28->31
	$date = $_REQUEST['date'];
	$todate = $_REQUEST['todate'];
	$fromdate = $_REQUEST['fromdate'];
	if ($date != "") {
		if ( strlen($date) == 8 ) {
			$lowerbound = $date . "000000";
			$upperbound = $date . "000000";
		}
	} else {
	// SET THE INVOICE PERIOD, TO and FROM have precedence
	if ( $todate != "" AND $fromdate != "" )
	{
		if ( strlen( $fromdate ) == 8 )
			$lowerbound = $fromdate . "000000";//000000: thá»�i gian hhmmss. VD: $lowerbound = 20090312000000
		else if ( strlen( $fromdate ) == 10 )
			$lowerbound = $fromdate . "0000";// 0000: náº¿u kÃ¨m giá»� báº¯t Ä‘áº§u hh

		if ( strlen( $todate ) == 8 )
			$upperbound = $todate . "235959";
		if ( strlen( $todate ) == 10 )
			$upperbound = $todate . "5959";
	}
	else
	{
		$mon = intval($mon);//Chuyá»ƒn sang kiá»ƒu INT
		$day = intval($d);
		

		if ( $mon < 10 )
			$mon = "0" . $mon;//Vd: 1 -> 01
		if ( $day < 10 )
			$day = "0" . $day;

		$lowerbound = $yr;
		$upperbound = $yr;
	
		// IF ALL MONTHS ARE SELECTED - SET TO JANUARY 1
		// All selected
		if ( $mon == 0 )
		{
			$lowerbound .= "0101000000";
			$upperbound .= "1231235959";
		}
		else
		{
			$lowerbound .= $mon;// $year.$mon
			$upperbound .= $mon;

			if ( $day == 0 )//All
			{
				$lowerbound .= "01000000";
				$upperbound .= $no_days . "235959";// Vd: thÃ¡ng 2 thÃ¬ $year.$mon."28235959"
			}

			// FIRST HALF OF MONTH
			else if ( $day == 50 )//First half
			{
				$first = ceil($no_days / 2);//ceil: láº¥y cháºµn trÃªn vd: 3.4 -> 4

				$lowerbound .= "01000000";// Tá»« ngÃ y 1
				$upperbound .= $first . "235959";//Ä�áº¿n ngÃ y no_days/2(khoang 15)
			}

			// SECOND HALF OF MONTH
			else if ( $day == 51 )//Second half
			{
				$second = ceil($no_days / 2) + 1;

				$lowerbound .= $second . "000000";
				$upperbound .= $no_days . "235959";
			}

			else
			{
				$lowerbound .= $day . "000000";
				$upperbound .= $day . "235959";
			}
		}
	}
	}

	
}

?>